/*
 * @(#)XfdmFuzzyCN2Selector.java        1.0 2000/05/09
 *
 * This file is part of Xfuzzy 3.0, a design environment for fuzzy logic
 * based systems.
 *
 * (c) 2000 IMSE-CNM. The authors may be contacted by the email address:
 *                    xfuzzy-team@imse.cnm.es
 *
 * Xfuzzy is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation.
 *
 * Xfuzzy is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */

package xfuzzy.xfdm.model.algorithm;

import xfuzzy.lang.*;

/**
 * Clase que describe un selector para el algoritmo FuzzyCN2
 * 
 * @author Pablo Mart�n Mu�oz
 *
 */
public class XfdmFuzzyCN2Selector {
	
	//----------------------------------------------------------------------------//
	//                            MIEMBROS PRIVADOS                               //
	//----------------------------------------------------------------------------//

	/**
	 * Indice de la variable del selector (variable del sistema) 
	 */
	private int varIndex;
	
	/**
	 * Etiqueta ling��stica del selector 
	 */
	private LinguisticLabel mf;
	
	/**
	 * Tipo de operador de relaci�n del selector 
	 */
	private int kind;
	
	/**
	 * Conjunto global de operadores 
	 */
	private Operatorset opSet;
	
	//----------------------------------------------------------------------------//
	//                                CONSTRUCTOR                                 //
	//----------------------------------------------------------------------------//

	/**
	 * Constructor basado en un conjunto de patrones "crisp"
	 */
	public XfdmFuzzyCN2Selector(Operatorset opSet) {
		this.opSet = opSet;
	}

	//----------------------------------------------------------------------------//
	//                             M�TODOS P�BLICOS                               //
	//----------------------------------------------------------------------------//
	
	/**
	 * M�todo que computa el selector para un patr�n
	 */
	public double compute(double[] input) {
		double value = input[this.varIndex];
		double result = 0.0;
		switch (this.kind) {
			case Relation.IS:
				result = this.mf.compute(value);
				break;
			case Relation.ISNOT:
				result = this.opSet.not.compute(this.mf.compute(value));
				break;
			case Relation.GR_EQ:
				result = this.mf.greatereq(value);
				break;
			case Relation.SM_EQ:
				result = this.mf.smallereq(value);
				break;
			case Relation.GREATER:
				result = this.opSet.not.compute(this.mf.smallereq(value));
				break;
			case Relation.SMALLER:
				result = this.opSet.not.compute(this.mf.greatereq(value));
				break;
			case Relation.APP_EQ:
				result = this.opSet.moreorless.compute(this.mf.compute(value));
				break;
			case Relation.VERY_EQ:
				result = this.opSet.very.compute(this.mf.compute(value));
				break;
			case Relation.SL_EQ:
				result = this.opSet.slightly.compute(this.mf.compute(value));
				break;
		}
		return result;
	}
	
	/**
	 * Obtiene el indice de la variable del selector (variable del sistema) 
	 */
	public int getVarIndex() {
		return varIndex;
	}

	/**
	 * Asigna el indice de la variable del selector (variable del sistema) 
	 */
	public void setVarIndex(int varIndex) {
		this.varIndex = varIndex;
	}

	/**
	 * Obtiene la etiqueta ling��stica del selector  
	 */
	public LinguisticLabel getMf() {
		return mf;
	}

	/**
	 * Asigna la etiqueta ling��stica del selector
	 */
	public void setMf(LinguisticLabel mf) {
		this.mf = mf;
	}

	/**
	 * Obtiene el tipo de operador de relaci�n del selector
	 */
	public int getKind() {
		return kind;
	}

	/**
	 * Asigna el tipo de operador de relaci�n del selector
	 */
	public void setKind(int kind) {
		this.kind = kind;
	}

	/**
	 * Obtiene el conjunto de operadores
	 */
	public Operatorset getOpSet() {
		return opSet;
	}

	/**
	 * Asigna el conjunto de operadores 
	 */
	public void setOpSet(Operatorset opSet) {
		this.opSet = opSet;
	}

}
